home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / rtgmaster_dev / demos / flame / timer.c < prev    next >
C/C++ Source or Header  |  1996-02-18  |  1KB  |  61 lines

  1. /*
  2.     Timer Module
  3.  
  4.     Time measuring routines
  5.  
  6. */
  7. //* "Includes"
  8. //#include <global.h>
  9. //*
  10. //* "Globals"
  11. #include <clib/exec_protos.h>
  12. #include <pragmas/exec_pragmas.h>
  13. #include <exec/memory.h>
  14. #include <devices/timer.h>
  15. #include <clib/timer_protos.h>
  16. #include <pragmas/timer_pragmas.h>
  17.  
  18. struct timerequest *TimeIO;
  19. struct Library *TimerBase;
  20. struct EClockVal *t1,*t2;
  21. ULONG E_Freq;
  22. //*
  23. //* "InitTimer"
  24. BOOL InitTimer(void) {
  25.  
  26.     TimeIO = (struct timerequest *)AllocMem(sizeof(struct timerequest), MEMF_CLEAR|MEMF_PUBLIC);
  27.     if (!TimeIO) return FALSE;
  28.     if (OpenDevice((STRPTR)"timer.device", UNIT_ECLOCK, (struct IORequest *)TimeIO, 0L))
  29.         return FALSE;
  30.     t1=AllocMem(sizeof(struct EClockVal), MEMF_CLEAR|MEMF_PUBLIC);
  31.     if (!t1) return FALSE;
  32.     t2=AllocMem(sizeof(struct EClockVal), MEMF_CLEAR|MEMF_PUBLIC);
  33.     if (!t2) return FALSE;
  34.     TimerBase = (struct Library *)(TimeIO->tr_node.io_Device);
  35.     return TRUE;
  36. }
  37. //*
  38. //* "CloseTimer"
  39. void CloseTimer(void) {
  40.     if (TimeIO) CloseDevice((struct IORequest *)TimeIO);
  41.     if (t1) FreeMem(t1,sizeof(struct EClockVal));
  42.     if (t2) FreeMem(t2,sizeof(struct EClockVal));
  43.     if (TimeIO) FreeMem(TimeIO, sizeof(struct timerequest));
  44. }
  45. //*
  46. //* "StartClock"
  47. void StartClock(void) {
  48.     E_Freq = ReadEClock(t1);
  49. }
  50. //*
  51. //* "StopClock"
  52. ULONG StopClock(void) {
  53.     register ULONG frames;
  54.     E_Freq = ReadEClock(t2);
  55.     frames = t2->ev_lo - t1->ev_lo;
  56.     if (frames==0) return 0;
  57.     return E_Freq/frames;
  58. }
  59. //*
  60.  
  61.